package com.github.tommas.admintpl.config;

import com.github.tommas.admintpl.bean.filestorage.FileStorage;
import com.github.tommas.admintpl.bean.filestorage.LocalFileStorage;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FileStorageConfiguration {
    private static final String LOCAL_ENGINE = "local";
    private static final String MINIO_ENGINE = "minio";

    @Value("${file-storage.engine}")
    private String engine;
    @Value("${file-storage.local.storage-dir:null}")
    private String localStorageDir;

    @Bean
    public FileStorage fileStorage() {
        if (LOCAL_ENGINE.equals(engine)) {
            return new LocalFileStorage(localStorageDir);
        }

        throw new RuntimeException(String.format("Unknown storage engine: %s", engine));
    }
}
